package indexingSystem;

import java.util.Vector;

public class TermFrequencyVector {
	private double magnitude;
	private Vector<Double> frequency_vector;
	TermFrequencyVector(Vector<Double> vector) {
		frequency_vector = vector;
		magnitude = 0;
		for(Double freq : frequency_vector) {
			magnitude += freq*freq; 
		}
		magnitude = Math.sqrt(magnitude);
	}
	public double getMagnitude() {
		return magnitude;
	}
	public double getIndex(int idx) {
		return frequency_vector.elementAt(idx);
	}
	public double distanceTo(TermFrequencyVector other) {
		double mag = this.getMagnitude() * other.getMagnitude();
		int sum = 0;
		int length = this.frequency_vector.size();
		for(int i = 0; i < length; i++)
			sum += this.getIndex(i) * other.getIndex(i);  
		return sum/mag;
	}
	public Vector<Double> add(Vector<Double> other) {
		Vector<Double> sum = new Vector<Double>();
		for (int i = 0; i < frequency_vector.size(); i++)
			sum.set(i, frequency_vector.elementAt(i) + other.elementAt(i));
		return sum;
	}
	public int length() {
		return frequency_vector.size();
	}
}
